package com.example.graphictest;


public class Circle {

	private float posX;
	private float posY;
	private float radius;
	private boolean isSelected;
	private float speedX;
	private float speedY;
	private float mass;
	private int color;
	private static final float gravityY = 9.8f * 100.0f;

	public Circle(int x, int y, int r, int c) {
		posX = x;
		posY = y;
		radius = r;
		isSelected = false;
		speedX = 0;
		speedY = 0;
		mass = radius * radius; // pi * r^2 
		color = c;
	}

	public boolean checkInside(float x, float y) {
		if (x >= posX - radius && y >= posY - radius && x <= (posX + radius)
				&& y <= (posY + radius))
			isSelected = true;
		else
			isSelected = false;

		return isSelected;
	}

	public void updatePos(float x, float y, int moveSpeed) {

		if (isSelected) {
			posX =  (x * moveSpeed + posX * (16 - moveSpeed)) / 16;
			posY =  (y * moveSpeed + posY * (16 - moveSpeed)) / 16;
		}

	}

	public void setSpeed(float inSpeedX, float inSpeedY) {
		if (isSelected) {
			//speedX = Math.min(20, inSpeedX);
			//speedY = Math.min(20, inSpeedY);
			speedX = inSpeedX;
			speedY = inSpeedY;
		}
	}

	public void updatePosDeltaTime(float deltaTime, int boundaryX, int boundaryY) {
		//if (isSelected) {
			
		float speedXDeltaTime = speedX * deltaTime;
		float speedYDeltaTime = speedY * deltaTime;
		//float speedYDeltaTime = (speedY + gravityY) * deltaTime;
		
			if( posX + speedXDeltaTime + radius > boundaryX )
			{
				posX = boundaryX - radius;
				speedX = -speedX;
			}
			else if( posX + speedXDeltaTime - radius < 0)
			{
				posX = 0 + radius;
				speedX = -speedX;
			}
			else
			{
				posX += speedXDeltaTime;
			}
			
			if( posY + speedYDeltaTime + radius > boundaryY )
			{
				posY = boundaryY - radius;
				speedY = -speedY;
			}
			else if( posY + speedYDeltaTime - radius < 0)
			{
				posY = 0 + radius;
				speedY = -speedY;
			}
			else
			{
				posY += speedYDeltaTime;
			}
			speedY += gravityY * deltaTime;
			

		//}
	}

	public float getPosX() {
		return posX;
	}

	public void setPosX(float posX) {
		this.posX = posX;
	}

	public float getPosY() {
		return posY;
	}

	public void setPosY(float posY) {
		this.posY = posY;
	}

	public float getRadius() {
		return radius;
	}

	public void setRadius(float radius) {
		this.radius = radius;
	}

	public boolean isSelected() {
		return isSelected;
	}

	public void setSelected(boolean isSelected) {
		this.isSelected = isSelected;
	}

	public float getSpeedX() {
		return speedX;
	}

	public void setSpeedX(float speedX) {
		this.speedX = speedX;
	}

	public float getSpeedY() {
		return speedY;
	}

	public void setSpeedY(float speedY) {
		this.speedY = speedY;
	}

	public float getMass() {
		return mass;
	}

	public void setMass(float mass) {
		this.mass = mass;
	}

	public int getColor() {
		return color;
	}

	public void setColor(int color) {
		this.color = color;
	}


}
